// 我的申报
import React from 'react';
import './myDeclare.scss';
import BreadcrumbNav from '../../../component/breadcrumb/breadcrumb'
import { Row, Col, Space, Checkbox , Pagination, Calendar, Table ,Button } from 'antd';
import cookie from 'react-cookies'
import { EditOutlined, DeleteOutlined ,SettingOutlined,LoadingOutlined, PlusOutlined ,UploadOutlined} from '@ant-design/icons';
import {applyList} from '../../../api/myWork'

class myDeclare extends React.Component {
	state = {
		apply_list: [],
	}
	componentWillMount(){
		this.columns = [
			{
                title: '#',
                dataIndex: 'index',
                key: 'index',
                align: 'center',
                width: 80,
                render: (text,record,index) => `${index+1}`,
            },
			{
				title: '编号',
				dataIndex: 'number',
				key: 'number',
			},
			{
				title: '申报类型',
				dataIndex: 'apply_type',
				key: 'apply_type',
				render:(apply_type)=>{
					if(apply_type == 1){
						return <span>设备型号新增</span>
					} else {
						return <span>项目创建</span>
					}
				}
			},
			{
				title: '对应项目',
				key: 'relative_remark',
				dataIndex: 'relative_remark',
			},
			{
				title: '申报人',
				dataIndex: 'create_u_name',
				key: 'create_u_name',
			},
			{
				title: '审批人',
				dataIndex: 'audit_u_name',
				key: 'audit_u_name',
			},
			{
				title: '审批状态',
				key: 'state',
				dataIndex: 'state',
				render:(state)=>{
					if(state == 1){
						return <span>审批中</span>
					} else if(state == 2) {
						return <span>审批成功</span>
					} else {
						return <span>审批失败</span>
					}
				}
			},
			{
				title: '最后提交时间',
				key: 'last_sub_time',
				dataIndex: 'last_sub_time'
			},
			{
			  title: '操作',
			  key: 'action',
			  render: (text, record) => {
				return <Space size="middle">
					{text.state == 3 ?
					<a style={{ marginRight:'6px', color:'#2F3CF2'}} className="link" onClick={this.toAddNewPro.bind(this, text)}>查看详情</a> :''}
					{text.state == 1 || text.state == 2 ?
					<a style={{ marginRight:'6px', color:'#2F3CF2'}} className="link" onClick={this.toAddNewPro.bind(this, text)}>查看详情</a> :''}
				</Space>
			  },
			},
		];
    }
	componentDidMount() {
		this.getData()
	}
	// 获取数据
	getData = () => {
		let post_data = {
            auth_token:cookie.load('station_console_setting_web_login').auth_token,
			type:'1'
        }
		applyList(post_data).then( res => {
			console.log(res,'我的申报数据');
			this.setState({
				apply_list:res.data.apply_list
			})
		})
	}

    // state ==1/2 查看详情 state == 3 编辑新增设备维修中
	toAddNewPro = (val) => {
		console.log(val,1111111111);
		if(val.apply_type == 1){
			if(val.state == 1 || val.state == 2) {
				this.props.history.push({
					pathname: '/index/deviceLibrary/deviceList/deviceInfo',
					state:{look:'true',relative_id:val.relative_id,approvalAndDeclaration:'approvalAndDeclaration'}})
				// window.location.href=`/index/deviceLibrary/deviceInfo?look=${true}&relative_id=${val.relative_id}&approvalAndDeclaration=approvalAndDeclaration`
			} else {
				console.log(22222222222);
				this.props.history.push({
					pathname: '/index/deviceLibrary/deviceList/deviceInfo',
					state:{spu_id:val.relative_id,myDeclare:'myDeclare'}})
				// window.location.href=`/index/deviceLibrary/addNewType?spu_id=${val.relative_id}&myDeclare=myDeclare`
			}
		}else{
			window.location.href=`/index/hardwareCenter/programConfig#/programConfigDetail?id=${val.relative_id}&type=${3}&state=${val.state}`
		}
    }
	render() {
        const {apply_list} = this.state;
		
		return (
            <Row className="myDeclare" id="ContentMainList">
                        <Col span={24}  className="myDeclare_son">
							<div style={{height:'100px',margin:'30px'}} >
								<BreadcrumbNav />
							</div>
                            <div className="titleInfo" >
                                <div></div>
                                <div><span onClick={this.tofmywsb}>我的申报 </span></div>
                            </div>
                            <div className="un_tableinfo">
							     <Table  dataSource={apply_list}  columns={ this.columns}  pagination={false} locale={{emptyText: '暂无数据'}}></Table> 
							</div>
                        </Col>
			</Row>
		)
	}
}
export default myDeclare;